/**
 * Copyright:Copyright(c)2014-2017
 * Company:厦门市易致达物联网科技有限公司
 * @version 1.0
 */
package shop.controller.front.voucher;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import shop.core.FrontBaseController;
import shop.core.Services;
import shop.core.common.bean.JSONResult;
import shop.services.front.voucher.VoucherService;
import shop.services.front.voucher.bean.Voucher;
import shop.services.front.voucherhave.VoucherhaveService;
import shop.services.front.voucherhave.bean.Voucherhave;
import shop.services.manage.system.bean.User;
import shop.services.manage.system.impl.UserService;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

/**   
 * @类名称：VoucherController
 * @创建人：Wzl
 * @创建时间：2018-01-03 下午16:55:48      
 * @版本号：1.0
 * @描述：     
 */
@Controller
@RequestMapping("/front/voucher/")
public class VoucherController extends FrontBaseController<Voucher> {
    @Resource
    private VoucherService voucherService;
    @Resource
    private UserService userService;
    @Resource
    private VoucherhaveService voucherhaveService;
    @Override
    public Services<Voucher> getService() {
        return voucherService;
    }

    /**
     * 跳转到积分商城页面（礼卷列表）
     *
     * @return
     */
    @RequestMapping("toShopList")
    public String toShopList() {
        return "/front/scoreShop/shopList";
    }

    /**
     * 跳转到兑换礼卷页面（礼卷详情）
     *
     * @return
     */
    @RequestMapping("toExchange")
    public String toExchange() {
        return "/front/scoreShop/exchange";
    }

    /**
     * 跳转到礼卷列表页面
     *
     * @return
     */
    @RequestMapping("toVoucherList")
    public String toVoucherList() {
        return "/front/voucher/voucherList";
    }

    /**
     * 跳转到选择礼卷页面
     *
     * @return
     */
    @RequestMapping("toChooseVoucher")
    public String toChooseVoucher() {
        return "/front/voucher/selectVoucher";
    }

    /**
     * 跳转到生成礼卷页面
     *
     * @return
     */
    @RequestMapping("toSetVoucher")
    public String toSetVoucher() {
        return "/front/voucher/setVoucher";
    }

    /**
     * 跳转到领取礼卷页面
     *
     * @return
     */
    @RequestMapping("toGetVoucher")
    public String toGetVoucher() {
        return "/front/voucher/getVoucher";
    }

    /**
     * 查询礼卷列表
     *
     * @return
     * @throws Exception
     */
    @RequestMapping("selectVoucherList")
    @ResponseBody
    public JSONResult selectVoucherList(Voucher voucher){
        List<Voucher> voucherList = voucherService.selectVoucherList(voucher);
        JSONResult jsonResult = new JSONResult();
        jsonResult.setData(voucherList);
        return jsonResult;
    }

    /**
     * 查询用户订单礼卷列表
     * @param voucherID
     * @return
     */
    @RequestMapping(value = "selectOrderVoucherList", method = RequestMethod.GET)
    @ResponseBody
    public JSONResult selectOrderVoucherList(String voucherID) {
        String[] voucherIDs = voucherID.split(",");
        List<Voucher> voucherList=new ArrayList<>();
        if(voucherIDs.length>0&&!"0".equals(voucherID)){
            for(int i=0;i<voucherIDs.length;i++){
                Voucher voucher=new Voucher();
                voucher.setId(voucherIDs[i]);
                voucher=voucherService.selectOne(voucher);
                voucherList.add(voucher);
            }
        }
        jsonResult = new JSONResult();
        jsonResult.setData(voucherList);
        return jsonResult;
    }
}
